package com.wenhai.concurrency.thread;

/**
 * @ClassName ThreadLocalDemo
 * @Description
 * @Author 谢文海
 * @Date 2021/4/9 0:58
 * @Version 1.0
 **/
public class ThreadLocalDemo {
    static ThreadLocal<String> localVariable = new ThreadLocal<>();
    static void print(String string) {
        System.out.println(string + ":" + localVariable.get());
    }

    public static void main(String[] args) {
        Thread threadA = new Thread(()->{
            localVariable.set("threadA local variable");
            print("threadA");
            System.out.println("threadA remove after : " + localVariable.get());
        });

        Thread threadB = new Thread(()->{
            localVariable.set("threadB local variable");
            print("threadB");
            System.out.println("threadB remove after : " + localVariable.get());
        });
        threadA.start();
        threadB.start();
    }
}
